package com.ibm.cloud.banking.media.service;

import com.ibm.cloud.banking.annotation.PBS;
import com.ibm.cloud.banking.facade.media.IMediaCardFacade;
import com.ibm.cloud.banking.facade.media.dto.MediaCardDTO;
import com.ibm.cloud.banking.platform.context.service.RequestContextHandler;
import com.ibm.cloud.invoker.PbsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@PBS(servNo = "PBS300001")
@Slf4j
public class AllocateMediaCardService implements PbsService<MediaCardDTO, MediaCardDTO> {

    @Autowired
    IMediaCardFacade mediaCardFacade;

    private final static String COMPENSATE_PARAMS_KEY = "allocate-media-card-param-key";

    @Override
    public MediaCardDTO doService(MediaCardDTO mediaCardDTO) {
        RequestContextHandler.putCompensate(COMPENSATE_PARAMS_KEY,mediaCardDTO);
        return mediaCardFacade.allocateMediaCard(mediaCardDTO);
    }

    @Override
    public void compensate(MediaCardDTO data) {
        data = (MediaCardDTO)RequestContextHandler.getCompensate(COMPENSATE_PARAMS_KEY);
        mediaCardFacade.allocateMediaCardRefund(data);
    }
}
